package com.tourism.controller;

import com.tourism.entity.Area;

import com.tourism.exception.GlobalException;
import com.tourism.service.AreaService;
import com.tourism.util.common.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author z
 * @Date 2021-04-25 9:12
 */
@RestController
@RequestMapping("/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 新增地区
     *
     * @return
     */
    @PostMapping("/addArea")
    @ResponseBody
    public Response addArea(@RequestBody Area area) throws GlobalException {

            return Response.success(areaService.addArea(area));

    }
    /**
     * 修改地区
     *
     * @param area
     * @return
     */
    @PostMapping("/updateArea")
    @ResponseBody
    public Response updateArea(@RequestBody Area area) {
        return Response.success(areaService.updateArea(area));

    }

    /**
     * 查询地区列表
     *
     * @return
     */
    @GetMapping("/getAllArea")
    @ResponseBody
    public List<Area> getAllArea(String name) {
        return areaService.getAllArea(name);
    }

    /**
     * 根据景点id删除地区信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteAreaById")
    @ResponseBody
    public Response deleteAreaById(Long id) {
        return Response.success(areaService.deleteAreaById(id));
    }
}
